home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / pavt117.zip / PAVT117.DOC < prev    next >
Text File  |  1991-12-23  |  22KB  |  496 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.                            PAvatar 1.17
  15.              Turbo Pascal Avatar level 1 Console Kit
  16.                 Copyright c 1991 Gregory P. Smith
  17. Part I.  Introduction
  18. =======================================
  19.  
  20.      This toolkit represents hundreds of hours of programming that 
  21. resulted in this fast and accurate  product.  PAvatar  is a  Turbo 
  22. Pascal unit (version 5.5 or later) that can provide your  programs 
  23. with Avatar level 1  console, extended  Avatar level  0+ (optional 
  24. ANSI fallback), ANSI-BBS, and ANSI terminal  emulations.  This  is 
  25. done with a series of procedural hooks for  screen I/O  and cursor 
  26. control.  This allows you to use  the procedures  of your  choice, 
  27. making the unit the most flexible of its type.
  28.      An  added  bonus to  using this  unit is  DESQview awareness.  
  29. This unit contains facilities  for detecting  DESQview, giving  up 
  30. the  time  slice,  and  using  DESQview's  video buffer.   This is 
  31. especially valuable for communications and bbs type programs  that 
  32. are often run under DESQview.
  33.  
  34.  
  35. Requirements
  36. ---------------------------
  37.  
  38.      This  unit  requires  that  you are  using an  IBM compatible 
  39. computer and have Turbo Pascal 5.5 or later.  As I  have used  OOP 
  40. for fast and efficient data management within this unit; I  regret 
  41. that I  cannot provide  a Turbo  Pascal 5.0  version of  the PAvt1 
  42. unit.
  43.      Memory requirements within a program using PAvatar have  been 
  44. kept to a minimum.  Only 3-4k of heap space as  well as  less than 
  45. 500 bytes stack space.  The actual code itself only requires 16k.
  46.  
  47. Shareware
  48. ---------------------------
  49.  
  50.      I am distributing this unit under a relaxed shareware concept 
  51. so as to promote Avatar.  You are free  to use  the compiled  unit 
  52. however you want, as  long as  I'm given  credit for  the terminal 
  53. emulations  somewhere  in  the  documentation  or  in the  program 
  54. itself.  Please let me know of any programs  that you  write using 
  55. PAvatar so that I can recommend them to others.
  56.      If you want the source code to this unit it is available  for 
  57. $10 U.S.,  see the  registration form  for details.   The possible 
  58. benefits  of  having  source  code  are  described  later  in this 
  59. document.
  60.  
  61. Liability
  62. ---------------------------
  63.  
  64.      To use PAvatar you  must first  agree that  I cannot  be held 
  65. responsible for any damages or problems that occur from its use or 
  66. misuse.  If you do not agree to these terms don't use this unit.
  67.  
  68. Part II.  QUICK START
  69. =======================================
  70.  
  71.      First off you must  install your  unit.  To  do so,  copy the 
  72. appropriate TPU  file into  your units  directory (the  TPU's have 
  73. been renamed to .T55  for TP  5.5 and  .T60 for  TP 6.0,  you must 
  74. rename yours).  Next, copy the demo program PAVTDEMO.PAS into your 
  75. pascal directory.  Type TPC pavtdemo or  compile it  to disk  from 
  76. the IDE.  You now have a utility for displaying AVT/1, AVT/0+, and 
  77. ANSI files that is  DESQview aware.   Unless you're  a Sysop,  you 
  78. probably don't have lots  of .AVT  Avatar files.   Currently there 
  79. are not many Avatar editors, but you may use my ANSI to  Avatar/0+ 
  80. converter  to  create  Avatar  files.   It's  found  on  BBS's  as 
  81. A2AVTnnn.ZIP where  nnn is  the version  number (currently  2.10).  
  82. When typing level 0 files, be sure to use the  /PLUS parameter  to 
  83. indicate  that  it  is  not a  level 1  file (The  differences are 
  84. described later).
  85.  
  86. Part III.  Interface
  87. =======================================
  88.  
  89. Procedures
  90. ---------------------------
  91.  
  92.      PAvatar is a self sufficient unit in that only two procedures 
  93. are required to add an Avatar  or ANSI  terminal to  your program.  
  94. However, there are more than two procedures available so that  you 
  95. can take  advantage of  many special  features of  the unit.   The 
  96. procedures and definitions follow.
  97.  
  98. Procedure Parse_AVT1 (ch:char);
  99.  
  100.     This is the main procedure of the unit.  It takes character ch 
  101.     and parses it according to the  status.  For  instance if  you 
  102.     pass it a ^V it would go into the Avatar command mode in which 
  103.     the next character would represent an  Avatar command.   If it 
  104.     were an Esc and ANSI was enabled, the next character passed to 
  105.     it would be tested for a bracket '[' or a  shorter VT52  style 
  106.     ANSI commands.  This is the heart of the whole unit.
  107.  
  108. Procedure ResetTerminal (nc,nl:byte);
  109.  
  110.     This procedure is used  to Reset  the Terminal  emulation with 
  111.     screen dimensions nc columns  and nl  lines.  It  always takes 
  112.     you back  to the  original mode  with AVT/1  active, and  ANSI 
  113.     fallback turned off.  It has the same effect as issuing a ^V^R 
  114.     to the AVT/1 parser.
  115.  
  116. Procedure SetScreen(nc,nl:byte);
  117.  
  118.     Use this procedure when  you want  to change  the size  of the 
  119.     terminal screen without resetting  everything else  as in  the 
  120.     ResetTerminal  procedure.   The only  thing this  does is  re- 
  121.     define all of the  Avatar windows  to have  nc columns  and nl 
  122.     lines.
  123.  
  124. Procedure AvtInterp (ch:char);
  125.  
  126.     This procedure is called by the Parser to interpret the Avatar 
  127.     codes  after  DLE's  and  special  considerations   have  been 
  128.     processed.  When in ANSI_Only or AVT/0+ mode you can use  this 
  129.     instead of Parse_AVT1.  The extra overhead of Parse_AVT1 is so 
  130.     small that using this is usually not worth it.
  131.  
  132. Procedure AvtTTY (ch:char);
  133.  
  134.     This procedure is called by the AVT/1 Parser when a  character 
  135.     is not part of a control code.  It simply writes  character ch 
  136.     to  the  screen  following  the  current  Avatar window  setup 
  137.     (including  flow,   insert,  direction,   etc..).   The   only 
  138.     characters that it processes are CR,  LF, BS,  Tab, and  Bell.  
  139.     You should not need this procedure, but it's here if you do.
  140.  
  141. Procedure Level0_Simulation (fallbck:boolean);
  142.  
  143.     This procedure places the interpreter into an extended  AVT/0+ 
  144.     emulation mode.  If fallbck is true ANSI fallback will be  on.  
  145.     Internally, this procedure re-configures  AVT/1's window  0 to 
  146.     have a default color of cyan  (3), as  well as  turning cooked 
  147.     mode off.  Using this procedure is more effective than sending 
  148.     the equivalent codes for defining a  level 0  simulation in  a 
  149.     certain window.  Destructive backspaces are also disabled.
  150.  
  151. Procedure ANSI_Only;
  152.  
  153.     Use this procedure when you want to place  the parser  in ANSI 
  154.     Only mode.  It is the equivalent of putting  the AVT/1  parser 
  155.     to sleep and disabling fallback.  This is faster than fallback 
  156.     mode.
  157.  
  158. Procedure AvtSound (note:byte; oct:shortint; dur:byte);
  159.  
  160.     This procedure is a shortcut to  stuff music  into the  Avatar 
  161.     sound buffer without having to send  the code  to the  parser.  
  162.     Note  represents  the musical  note in  the same  method which 
  163.     AVT/1's ^V^S command uses it.  That is note is equal  to (tone 
  164.     - 'A') * 2 + sharp  where tone  is somewhere  between 'A'  and 
  165.     'G'.  Sharp is a 0 or  a 1  as the  case may  be.  A  pause is 
  166.     generated by a note of 14 or greater.  The octave is a  signed 
  167.     integer in oct where 0 represents middle octave and 1 the next 
  168.     highest, -1 the next lowest.  Dur is the duration in tenths of 
  169.     a second.  If two identical notes  are queued  in a  row, they 
  170.     will be played legato so that they run together.
  171.  
  172. Procedure StuffSound (frq,dur:integer);
  173.  
  174.     This procedure is called by the above procedure.   It is  used 
  175.     to place a sound of frq hertz and dur tenths of a  second into 
  176.     the Sound buffer.  If the buffer is full,  it will  wait until 
  177.     space is available.
  178.  
  179. Procedure Set_Sound_backg(backg:boolean);
  180.  
  181.     All sounds produced by the PAvt unit, including  the ^G  bell, 
  182.     will  be  made  in  the background  if backg  is set  to true.  
  183.     Otherwise they will be  made in  the foreground,  delaying the 
  184.     program until they finish.  Sound defaults  to the  background 
  185.     as that is the preferred method for AVT/1.  It is worth noting 
  186.     that with foreground sound  the timer  interrupt ($1c)  is not 
  187.     chained and/or DESQview sound calls are not made.
  188.  
  189. Function DESQview_version: word;
  190.  
  191.     This is the first of the DESQview supportive routines in  this 
  192.     unit.  The DESQview major version number is in the high  byte, 
  193.     while  the  minor  version  is  in  the low  byte.  A  zero is 
  194.     returned if DESQview is not loaded.
  195.  
  196. Procedure DV_Pause;
  197.  
  198.     This procedure will give up the current time slice if  you are 
  199.     in DESQview.  It does nothing otherwise.   Use this  procedure 
  200.     when your program is  not doing  anything, to  give the  other 
  201.     programs more processing time.   Do not  hesitate to  use this 
  202.     procedure, it's written in  assembler so  that it's  execution 
  203.     time isn't even measurable.
  204.  
  205. Function ReadKey: char;
  206.  
  207.     This is a replacement for the Crt unit's ReadKey that gives up 
  208.     the current DESQview time slice (via DV_Pause) if a key hasn't 
  209.     been pressed.  
  210.  
  211. Function In_Command: boolean;
  212.  
  213.     Returns a true value if the  interpreter is  in the  middle of 
  214.     processing  any  Avatar or  ANSI command.   This is  useful to 
  215.     prevent  strange  displays or  invalid commands  when aborting 
  216.     displays.
  217.  
  218. Procedure UpdateCursor(x,y:byte);
  219.  
  220.     This procedure is used  to update  the cursor  position within 
  221.     the current Avatar window to x,y.  If a 0 is passed for x, the 
  222.     cursor will be reset to the correct position stored internally 
  223.     by the parser.
  224.  
  225. Variables
  226. ---------------------------
  227.  
  228.      There are only a  few non-procedural  variables that  you can 
  229. use to check or modify the status of the terminal.   They are  all 
  230. static variables with defined defaults.
  231.  
  232. ANSI_BBS : boolean = False;
  233.  
  234.     Use this variable to decide whether  the ANSI  portion of  the 
  235.     unit will use the "BBS" style.  The only differences when this 
  236.     is true are that Esc[2J also homes the  cursor and  Esc[J acts 
  237.     the same as Esc[2J instead of Esc[0J.  DOS's  own ANSI.SYS  is 
  238.     infamous for processing Esc[2J this way.
  239.  
  240. Fallback : boolean = False;
  241.  
  242.     This variable controls whether ANSI fallback will be on during 
  243.     Avatar emulations.  It is best not to mess with this  variable 
  244.     when using  AVT/1 as  it is  designed primarily  for use  with 
  245.     AVT/0+.
  246.  
  247. ScrnLines : byte = 25;
  248.  
  249.     This variable simply defines the number of lines that you want 
  250.     on your terminal screen.  Modifying this variable can  produce 
  251.     strange results.  It is recommended that you use the SetScreen 
  252.     procedure to define the screen size.
  253.  
  254. ScrnColumns : byte = 80;
  255.  
  256.     This variable is the partner of the above one.  It defines the 
  257.     number of columns you want on your terminal screen.  The  same 
  258.     restrictions apply with this variable as on the above.
  259.  
  260. QueryReply : string[80] = 'AVT1, Avatar/1 Console Copr.  1991 Greg
  261.                            Smith. Ver 1.17'+^M;
  262.  
  263.     When the Avatar terminal id request  is received  this is  the 
  264.     string that will be returned.  The "AVT1," at the beginning is 
  265.     important to the remote terminal.  It  is used  to define  the 
  266.     capabilities of the terminal.   Everything else  is just  your 
  267.     own logo or program ID.  In level 0+ simulation mode  the AVT1 
  268.     is changed to AVT0.
  269.  
  270. Sound_Stat : byte = 3;
  271.  
  272.     This variable is used to control which sounds are produced  by 
  273.     the unit.  If bit 1 is set then the unit can make sounds.  Bit 
  274.     0 only  controls the  bell (^G)  sound.  As  you can  see, the 
  275.     default is to have all sound enabled.
  276.  
  277. Dest_BS : boolean = True;
  278.  
  279.     As the name implies,  this variable  controls the  behavior of 
  280.     the  backspace  (^H)  character.   The  AVT/1   specifications 
  281.     require a Destructive backspace while the AVT/0 specifications 
  282.     require that it is non-destructive.
  283.  
  284. Constants
  285. ---------------------------
  286.  
  287.      The following constants are available for general use.
  288.  
  289.         Esc = ^[;
  290.         DLE = ^P;
  291.         FS = #28;
  292.         GS = #29;
  293.         RS = #30;
  294.         US = #31;
  295.         SP = #32; { space }
  296.  
  297.  
  298. User Hooks
  299. ---------------------------
  300.  
  301.      The  interface  for  this  unit has  been designed  to be  as 
  302. flexible  as  possible without  hindering the  performance of  the 
  303. unit.  Besides the main procedures and a few variables most  of it 
  304. is procedural hooks.  Their definitions follow.
  305.      The  Avatar  interpreter does  not check  for invalid  screen 
  306. coordinates on the hooks  that need  them.  It  is important  that 
  307. your  hooks  check  the  integrity of  the coordinates,  otherwise 
  308. seemingly  random  lockups  can  occur  when  invalid  or  garbled 
  309. commands are processed.
  310.  
  311. Query_Hook : ReplyProc = Procedure (S:String);
  312.  
  313.     This hook is used for all terminal queries  or responses  such 
  314.     as  the  Avatar  driver  query  and  the  ANSI  report  cursor 
  315.     position.   Usually  these  replies  will  be  placed  in  the 
  316.     keyboard buffer or sent out the comm port.   In pavtdemo,  the 
  317.     hook is left at its null procedure setting as there is no  use 
  318.     for it in that type of utility.  Note that information  passed 
  319.     to this hook should be inserted immediately into the input  or 
  320.     output buffer so that it is the next thing to be processed  if 
  321.     you wish to comply fully with the AVT/1 specifications.
  322.  
  323. WriteATh : WriteATHookT = Procedure (x,y,a:byte;ch:char);
  324.  
  325.     This hook is simple and important.  It should  write character 
  326.     ch on the screen at location x,y using  attribute a.   This is 
  327.     the  only  thing it  should do,  it should  not mess  with the 
  328.     cursor or scroll the screen.  The coordinates are one based.
  329.  
  330. GotoXYh : GotoXYHookT = Procedure (x,y:byte);
  331.  
  332.     This hook  is used  to set  the cursor  position.  Often  this 
  333.     routine  will  call the  Crt unit's  GotoXY procedure.   It is 
  334.     provided for flexibility and the possibility of using  PAvatar 
  335.     in  a  virtual  screen  or  window.   Full  checking   against 
  336.     ScrnLines and ScrnColumns is performed internally.
  337.  
  338. Scrollh : ScrollHookT = Procedure (dir,x1,y1,x2,y2,n,a:byte);
  339.  
  340.     This  hook  is important  to Avatar's  power.  It  scrolls the 
  341.     screen  region  of (x1,y1)-(x2,y2)  n lines  in the  direction 
  342.     indicated in dir (1=up, 2=down, 3=left,  4=right).  The  empty 
  343.     area created by the scroll should be filled with blank  spaces 
  344.     of color attribute a.  Most decent  windowing toolkits  have a 
  345.     procedure suitable for this.
  346.  
  347. FillAreah : FillHookT = Procedure (x1,y1,x2,y2,a:byte;ch:char);
  348.  
  349.     This hook is used to fill the screen region of (x1,y1)-(x2,y2) 
  350.     with character ch in attribute a.  If your scrolling procedure 
  351.     doesn't support a fill color for the newly exposed area,  this 
  352.     is a good procedure to use for it.
  353.  
  354. GetATh : GetCharHookT = Procedure (x,y:byte;var a:byte;var c:char);
  355.  
  356.     This hook is the  opposite of  the WriteATh  hook in  that its 
  357.     purpose it to retrieve information from the screen.   Variable 
  358.     parameters  c  and  a  should  be  set  to  the character  and 
  359.     attribute at the coordinates of x,y respectively.
  360.  
  361. HighAreah : HighHookT = Procedure (x1,y1,x2,y2,a:byte);
  362.  
  363.     Similar to FillAreah, this hook fills an area  of the  screen.  
  364.     The  area  defined by  (x1,y1)-(x2,y2) should  be filled  with 
  365.     attribute a, but the characters on  the screen  should not  be 
  366.     modified.
  367.  
  368. Pauseh : PauseHookT = Procedure (tenths:word);
  369.  
  370.     The  only  purpose of  this hook  is to  allow for  controlled 
  371.     system pauses.  This hook should pause the terminal for tenths 
  372.     tenths of a second.  The reason I didn't just use a delay(100) 
  373.     within  the  unit is  for the  protection of  the user.   With 
  374.     avatar, codes could be sent that  could conceivable  pause the 
  375.     system for several days.  It is up to you to  add a  method of 
  376.     breaking out of a pause such as a key press.
  377.  
  378. FlushInputh : Procedure;
  379.  
  380.     This hook has a default effect of zeroing the keyboard buffer.  
  381.     If your  program has  any internal  buffers or  communications 
  382.     buffer, you may wish to flush them when  this hook  is called.  
  383.     The Avatar flush input command calls this hook.
  384.  
  385. The PAvt0 Small Version
  386. ---------------------------
  387.  
  388.      Now included with the Pavt package is a  PAvt0 Small  version 
  389. of the unit.  This unit is an AVT/0+  and ANSI-BBS  terminal only.  
  390. It is much faster that the  AVT/1 unit  as there  are no  flow and 
  391. window controls.  The primary use for  this unit  is for  BBS door 
  392. programs which won't be using AVT/1.   Overall the  code there  is 
  393. 10.5k less code and 650 bytes less data as well as a  minimal heap 
  394. usage.  Compile the pavtdemo program with  the compiler  directive 
  395. of AVT0 for a demo of the PAvt0 unit.
  396.      The PAvt0 unit is designed as a drop  in replacement  for the 
  397. PAvt1  unit.   However there  are a  few procedures  and variables 
  398. which don't exist in the PAvt0 unit.  The  Pauseh and  FlushInputh 
  399. hooks are  not available,  the Level0_Simulation,  Parse_AVT1, and 
  400. Set_Sound_backg procedures are not available (AvtInterp  should be 
  401. used instead of Parse_AVT1),  and the  ANSI_BBS variable  is gone.  
  402. All of these were removed as they served no purpose in AVT/0+.  In 
  403. addition, this unit parses tab characters (^I) as 8 spaces instead 
  404. of the definable (defaults to 8 char tabs) tab stops  of the  full 
  405. unit.
  406.  
  407.  
  408. Part IV.  Special Considerations
  409. =======================================
  410.  
  411. Avatar 1 Console
  412. ---------------------------
  413.  
  414.      The  Avatar  level one  console is  a very  powerful terminal 
  415. emulation.  Naturally it goes without saying that there are a  few 
  416. things that must be considered if you wish to comply with the full 
  417. AVT/1 console specifications.  I've already mentioned the need  to 
  418. insert the query replies first into  the input  or output  buffer.  
  419. Secondly, AVT/1 features a sleep mode for its interpreter, so ANSI 
  420. fallback should not be used (but it will  work); a  remote program 
  421. using level 1 codes  should know  how to  switch between  sleeping 
  422. (ANSI) and awake (AVT/1).
  423.      The   main   thing   you   should  be   concerned  about   in 
  424. communications is flow control.   AVT/1 has  a way  to get  around 
  425. interference with XON/XOFF flow control if the parser is in cooked 
  426. mode,  but  if  it's  switched  to  raw mode,  the results  may be 
  427. disastrous.  As AVT/0+ is a raw  only terminal,  XON/XOFF must  be 
  428. disabled while it is active.
  429.  
  430. Tips & Tricks
  431. ---------------------------
  432.  
  433.      The  AvtInterp  procedure is  actually a  procedural variable 
  434. that is passed a character as its only parameter.  This should let 
  435. you know a lot about how PAvatar works internally, as well as  add 
  436. flexibility.  If you wish to add  your own  terminal, just  assign 
  437. your own procedures to  AvtInterp.  This  will work  when you  are 
  438. calling  AvtInterp  directly  instead  of Parse_AVT1.   Of course, 
  439. remember to call the parser when you switch to AVT/1.
  440.      If your program needs to execute a subprogram or shell to dos 
  441. there are some special precautions that you must  take.  You  must 
  442. call  the  Set_Sound_backg()  procedure   to  restore   the  timer 
  443. interrupt.  You should also save the exitproc as Set_Sound_backg() 
  444. only restores it to it's very  first state.   Here is  some sample 
  445. code for a dos shell:
  446.  
  447.      SavedEP := ExitProc;
  448.      Set_Sound_backg(False);
  449.      SwapVectors;
  450.      Exec(GetEnv('COMSPEC''),'');
  451.      SwapVectors;
  452.      Set_Sound_backg(True);
  453.      ExitProc := SavedEP;
  454.  
  455.  
  456. Part V.  History And Credits
  457. =======================================
  458.  
  459.      I thank Ping Hansen in the FidoNet pascal echo and an unknown 
  460. someone  in  the  FidoNet  communications  echo  for  sparking  my 
  461. interest in terminal emulations and Avatar.  I also would like  to 
  462. thank G. Adam Stanislav for taking on the project of  updating the 
  463. Avatar specification past its original Opus level commands.   Last 
  464. but not least, I would like  to thank  my parents  for putting  up 
  465. with me being on the computer so many hours.
  466.  
  467. Release Sites
  468. ---------------------------
  469.  
  470.      The  following  is a  list of  BBS's where  you can  find the 
  471. latest version of PAvatar as well as contacting me.
  472.  
  473. (303)779-4253  The Vault, 300-14400, Fido: 1:104/332
  474. (303)674-1305  Wizardry line 1, 1200-9600. Fido: 1:104/630,631
  475. (303)320-4078  CMOS BBS line 1,  300-9600, Fido: 1:104/441
  476. (303)322-4125  CMOS BBS line 2,  300-9600, Fido: 1:104/469
  477. (303)449-8946  Bohemia BBS Sys,  300-9600, (Unix System)
  478. (303)750-7136  Borealis WildCat, 1200-9600, RIME: ->BOREALIS
  479.  
  480.      Mark Cook, Sysop of Wizardry, is my only beta tester  at this 
  481. time.  I will acquire more as I feel the need.  He has  unconvered 
  482. most of the bugs hiding in PAvatar so far.  Thanks Mark!
  483.  
  484. ---------------------------------------------------------------------
  485.  
  486. Send all questions, comments, problems, ideas, money, etc.. to:
  487.  
  488.      Gregory P. Smith
  489.      4422 Pali Way
  490.      Boulder, CO. 80301 USA
  491.  
  492. Fidonet:  1:104/332,441,477,630,631
  493. RIME: ->BOREALIS
  494. UseNet/InterNet: gpsmith@bohemia.metronet.org
  495. CompuServe: Route to above internet address.
  496.